package cn.net.yugu.doraemon.common.jackson.serializer;

import cn.net.yugu.doraemon.common.util.MobileUtils;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;

public class MobilePhoneSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String phoneNumber, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeString(MobileUtils.maskPhoneNumber(phoneNumber));
        String field = gen.getOutputContext().getCurrentName();
        gen.writeStringField(field+"_encryption", MobileUtils.encryptMobile(phoneNumber));
    }
}